package com.market.service.impl;
import com.market.dto.GoodsDto;
import com.market.entity.Goods;
import com.market.mapper.GoodsMapper;
import com.market.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @ClassName GoodsServiceImpl
 * @Description TODO
 * @Author 1
 * @Date 2022/3/28 16:58
 * @Version 1.0
 */
@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;
    //新增商品
    @Override
    public boolean addGoods(Goods goods) {
        return goodsMapper.addGoods(goods)>0;
    }

    //上架商品
    @Override
    public boolean shelveGoods(int goodsId) {
        return goodsMapper.shelveGoods(goodsId)>0;
    }

    //下架商品
    @Override
    public boolean offShelveGoods(int goodsId) {
        return goodsMapper.offShelveGoods(goodsId)>0;
    }

    //删除商品
    @Override
    public boolean deleteGoods(int goodsId) {
        return goodsMapper.deleteGoods(goodsId)>0;
    }

    //修改商品属性（名称，售价，描述，每日可销售数量）
    @Override
    public boolean updateGoodsProperty(int goodsId,String goodsName,double price,String description,int typeId,int sellNum) {
        return goodsMapper.updateGoodsProperty(goodsId,goodsName,price,description,typeId,sellNum)>0;
    }

    //修改商品可销售数量
    public boolean updateGoodsSellNums(int goodsId,int newSellNum){
        return goodsMapper.updateGoodsSellNum(goodsId,newSellNum)>0;
    }

    //通过商品类别id查询商品
    @Override
    public List<Goods> queryGoodsByTypeId(int typeId) {
        return goodsMapper.queryGoodsByTypeId(typeId);
    }

    //通过商品id查询商品
    @Override
    public Goods queryGoodsByGoodsId(int goodsId) {
        return goodsMapper.queryGoodsByGoodsId(goodsId);
    }

    //根据商品名查询商品
    @Override
    public Goods queryGoodsByGoodsName(String goodsName) {
        return goodsMapper.queryGoodsByGoodsName(goodsName);
    }

    @Override
    public List<GoodsDto> queryGoodsByState() {
        return goodsMapper.queryGoodsByState();
    }

    @Override
    public List<Goods> queryAllGoods() {
        List<Goods> goods = goodsMapper.queryAllGoods();
        return  goods;
    }

    @Override
    public List<GoodsDto> queryByType(int typeId) {
        List<GoodsDto> goodsDtos = goodsMapper.queryByType(typeId);
        return goodsDtos;
    }
}
